home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1993 / MacHack 1993.toast / MacHack™ 1987-1992 / MacHack™ '90 / Source Code ƒ / C++ Files / HString.h < prev    next >
Encoding:
Text File  |  1990-05-02  |  1.3 KB  |  60 lines  |  [TEXT/QED1]

  1. // Copyright 1990 Waldemar Horwat.
  2. // Permission is granted for noncommercial use of this code.
  3.  
  4. typedef int bool;
  5.  
  6. struct StringData:HandleObject
  7.   {
  8.   int refCount;
  9.   char str[1]; //Variable length
  10.   };
  11.  
  12. class String
  13.   {
  14.  private:
  15.   StringData *data; // May be NIL!
  16.  
  17.   void internalCopy(const String &src);
  18.   OSErr internalCopy(const char *cString);
  19.   OSErr fresh();
  20.  
  21.  public:
  22.   // Cumulative error.
  23.   static OSErr err;
  24.  
  25.   // Constructors
  26.   String() {data=0;}
  27.   String(const String &src) {internalCopy(src);}
  28.   String(const char *cString) {internalCopy(cString);}
  29.  
  30.   // Destructor
  31.   ~String();
  32.  
  33.   // Clear the String to a null string.
  34.   void clear();
  35.  
  36.   // Assignment operators
  37.   String &operator=(const String &src);
  38.   OSErr operator=(const char *cString);
  39.  
  40.   // Query functions.
  41.   int length() const;
  42.   char operator[](int index) const;
  43.   String substr(int offset, int length) const;
  44.   //Result may move when heap is scrambled!
  45.   char *cString() const;
  46.  
  47.   bool operator==(const String &src2) const;
  48.  
  49.   // Concatenation
  50.   String operator|(const String &src) const;
  51.  
  52.   // Appending data to the end
  53.   OSErr operator|=(const String &src);
  54.   OSErr operator|=(char ch);
  55.   OSErr operator|=(char *cString);
  56.   // Prepending data to the beginning
  57.   OSErr operator^=(char ch);
  58.   OSErr operator^=(char *cString);
  59.   };
  60.